﻿import React from 'react';
import { Form, Input, Row, Col, Button, DatePicker,Icon, Select, Switch, Spin } from 'antd';
import './index.less'
import * as SelectTypes from '../../components/Form/CustomSelect';
import classNames from 'classnames';
const FormItem = Form.Item;
const Option = Select.Option;

class CompanyCard extends React.Component {

	constructor(props){
		super(props);
	}

  onNextClick(e) {
    e.preventDefault();
    this.props.form.validateFieldsAndScroll((errors, values) => {
      if (!!errors) {
        console.log('Errors in form!!!');
        return;
      }
      console.log("company:", values);
      this.props.onNextClick(values);
    });
  }

  onLastClick(e) {
    e.preventDefault();
    let values =this.props.form.getFieldsValue();
    this.props.onLastClick(values);
  }

	render() {
    let { company } = this.props;
    let { getFieldDecorator } = this.props.form;
    let {loading} = company;

		const container = (
			<Form horizontal>
				<Row gutter={16}>
					<Col sm={1}>
					</Col>
					<Col sm={10}>
						<FormItem	label="单位名称"	labelCol={{ span: 8 }}	wrapperCol={{ span: 16 }} required>
              {getFieldDecorator('name', { initialValue: company.name, rules: [{required: true}] })(<Input  />)}
            </FormItem>
						<FormItem	label="单位所在地"	labelCol={{ span: 8 }}	wrapperCol={{ span: 16 }} required>
              {getFieldDecorator('location', { initialValue: company.location, rules: [{required: true}] })(<Input  />)}
            </FormItem>
						<FormItem	label="组织机构代码"	labelCol={{ span: 8 }}	wrapperCol={{ span: 16 }} required>
              {getFieldDecorator('orgCode', { initialValue: company.orgCode, rules: [{required: true}] })(<Input  />)}
            </FormItem>
						<FormItem	label="单位性质"	labelCol={{ span: 8 }}	wrapperCol={{ span: 16 }} required>
              {getFieldDecorator('type', { initialValue: company.type, rules: [{required: true}] })(SelectTypes.CompanyTypeSelect)}
            </FormItem>
						<FormItem	label="邮政编码"	labelCol={{ span: 8 }}	wrapperCol={{ span: 16 }} required>
              {getFieldDecorator('zipCode', { initialValue: company.zipCode, rules: [{required: true}] })(<Input  />)}
            </FormItem>
						<FormItem	label="部门"	labelCol={{ span: 8 }}	wrapperCol={{ span: 16 }} required>
              {getFieldDecorator('department', { initialValue: company.department, rules: [{required: true}] })(<Input  />)}
            </FormItem>
						<FormItem	label="固定电话"	labelCol={{ span: 8 }}	wrapperCol={{ span: 16 }} required>
              {getFieldDecorator('telephone', { initialValue: company.telephone, rules: [{required: true}] })(<Input  />)}
            </FormItem>
						<FormItem	label="联系人"	labelCol={{ span: 8 }}	wrapperCol={{ span: 16 }} required>
              {getFieldDecorator('linkman', { initialValue: company.linkman, rules: [{required: true}] })(<Input  />)}
            </FormItem>

					</Col>
					<Col sm={10}>
						<FormItem	label="行业"	labelCol={{ span: 8 }}	wrapperCol={{ span: 16 }} required>
              {getFieldDecorator('industry', { initialValue: company.industry, rules: [{required: true}] })(<Input  />)}
            </FormItem>
						<FormItem	label="通讯地址"	labelCol={{ span: 8 }}	wrapperCol={{ span: 16 }} required>
              {getFieldDecorator('address', { initialValue: company.address, rules: [{required: true}] })(<Input  />)}
            </FormItem>
						<FormItem	label="工作职业类别"	labelCol={{ span: 8 }}	wrapperCol={{ span: 16 }} required>
              {getFieldDecorator('title', { initialValue: company.title, rules: [{required: true}] })(<Input  />)}
            </FormItem>
						<FormItem	label="是否接受档案"	labelCol={{ span: 8 }}	wrapperCol={{ span: 16 }}>
              {getFieldDecorator('receiveRecord', { initialValue: company.receiveRecord, rules: [{required: true}] })(SelectTypes.SwitchSelect)}
            </FormItem>
						<FormItem	label="是否接受户口"	labelCol={{ span: 8 }}	wrapperCol={{ span: 16 }}>
              {getFieldDecorator('receiveResidence', { initialValue: company.receiveResidence, rules: [{required: true}] })(SelectTypes.SwitchSelect)}
            </FormItem>
						<FormItem	label="签到单位"	labelCol={{ span: 8 }}	wrapperCol={{ span: 16 }} required>
              {getFieldDecorator('signCompany', { initialValue: company.signCompany, rules: [{required: true}] })(<Input  />)}
            </FormItem>
						<FormItem	label="签到单位所在地"	labelCol={{ span: 8 }}	wrapperCol={{ span: 16 }} required>
              {getFieldDecorator('signCompanyAddress', { initialValue: company.signCompanyAddress, rules: [{required: true}] })(<Input  />)}
            </FormItem>
						<FormItem	label="档案寄送地址"	labelCol={{ span: 8 }}	wrapperCol={{ span: 16 }} required>
              {getFieldDecorator('recordSendAddress', { initialValue: company.recordSendAddress, rules: [{required: true}] })(<Input  />)}
            </FormItem>
					</Col>
					<Col sm={3}>
					</Col>
				</Row>
				<Row type="flex" justify="center">
					<Button type="primary" onClick={this.onNextClick.bind(this)}>下一步</Button>
          &nbsp;&nbsp;&nbsp;
					<Button onClick={this.onLastClick.bind(this)}>上一步</Button>
				</Row>
			</Form>
		);

    return (
      <Spin spinning={loading}>{container}</Spin>
    );
	}
}

CompanyCard = Form.create()(CompanyCard);

export default CompanyCard;
